import wepy from 'wepy'
import {USER_MOBILE_BINDING,VIDEODETAIlDATA,IMAGEANDTEXTDETAILDATA,IMGTEXTCONSULTATIONDATA} from '@/utils/constant'
export default class tipsRegister extends wepy.mixin {
  data = {
    timer:null,
    article_seconds:null
  }

  methods = {
    cleartips() {
        this.clearTimer();
    }
  }

  async onShow() {
    wepy.getSetting({ success: res => {
        if((res.authSetting)['scope.userInfo']) { 
          if(this.$name == "videoDetail")
          {
            if(wepy.getStorageSync(VIDEODETAIlDATA))
            {
              this.article_seconds = wepy.getStorageSync(VIDEODETAIlDATA)[0].article_seconds;
            }
          }
          else if(this.$name == "imageAndTextDetail")
          {
            if(wepy.getStorageSync(IMAGEANDTEXTDETAILDATA))
            {
              this.article_seconds = wepy.getStorageSync(IMAGEANDTEXTDETAILDATA)[0].article_seconds;
            }
          }
          else if(this.$name == "imgTextConsultation")
          {
            if(wepy.getStorageSync(IMGTEXTCONSULTATIONDATA))
            {
              this.article_seconds = wepy.getStorageSync(IMGTEXTCONSULTATIONDATA)[0].article_seconds;
            }
          }
         //   this.isRegister(this.$name);
            this.$apply();
       }
    }})
  }

  onLoad() { 
  }
  //清除定时
  async clearTimer()
  {
    await clearInterval(this.timer) 
    this.timer = null;
    this.$apply();
  }
    async isRegister(pagename) {
        let userMobileBinding = wepy.getStorageSync(USER_MOBILE_BINDING);
        this.timer = await setTimeout(() => {
            if(!userMobileBinding)
            {
                wepy.showModal({
                title: '提示', //提示的标题,
                content: '您尚未注册，建议您注册，获取更多育儿信息！', //提示的内容,
                showCancel: false, //是否显示取消按钮,
                confirmText: '确定', //确定按钮的文字，默认为取消，最多 4 个字符,
                confirmColor: '#3CC51F', //确定按钮的文字颜色,
                success: res => {
                    if(res.confirm)
                    {
                        wepy.navigateTo({ url: 'register?pageurl=pages/'+pagename });
                    }
                }
                });
            }
        },this.article_seconds * 1000)
    }
}















